#include <bits/stdc++.h>
using namespace std;
const int N = 60;
int a[N];
int n;
void show() {
  for (int i = 1; i <= n; ++i) {
    cout << a[i] << ' ';
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) a[i] = i;
    reverse(a + 1, a + n + 1);
    show();
    for (int i = 1; i <= n - 1; ++i) {
      swap(a[i], a[i + 1]);
      show();
      swap(a[i], a[i + 1]);
    }
  }
}
